﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ProjectSem3.admin
{
    public partial class WebForm10 : System.Web.UI.Page
    {
        private DataClasses1DataContext dc = new DataClasses1DataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                join();
            }
        }

        protected void LinkButtonXoa_Click(object sender, EventArgs e)
        {
            try
            {
                LinkButton lb = (LinkButton)sender;
                HiddenField hd = (HiddenField)lb.Parent.FindControl("HiddenFieldNews");

                Artical ar = this.dc.Articals.Single(a => a.articalID == Convert.ToInt32(hd.Value));

                this.dc.Articals.DeleteOnSubmit(ar);
                this.dc.SubmitChanges();



                join();

                this.mesage_success.Visible = true;
                this.message_error.Visible = false;

            }
            catch
            {
                this.message_error.Visible = true;
                this.mesage_success.Visible = false;
            }
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            mesage_success.Visible = false;
        }
        public void join()
        {
            var atc = this.dc.Articals.Where(a => a.categoryID.Equals(4)).OrderByDescending(b => b.articalID);
            this.Repeater1.DataSource = atc.ToList();
            this.Repeater1.DataBind();
        }
    }
}